@Inject('disclosureService', '$stateParams', 'ngDialogService')
class technicalClarificaitonEditController {
  constructor() {
    this.data = {
      isEdit: false,
      activity: {},
    };

    this.view = {
      files: [],
    };

    this.getDetail($stateParams.id);
  }

  getDetail(id) {
    this.disclosureService.get(id)
      .then((res) => {
        if (res.success) {
          this.data.activity = res.data;
          this.view.files = this.data.activity.files;
          this.view.files.forEach((item) => {
            item.name = item.fileName;
          });
        } else {
          this.ngDialogService.alertError(res.message);
        }
      });
  }

  submitActivityForm() {
    this.data.activity.attachmentIds = this.view.files.map(item => item.id);
    this.disclosureService.update(this.data.activity)
      .then((res) => {
        if (res.success) {
          this.ngDialogService.alertSuccess('修改成功');
          window.history.go(-1);
        } else {
          this.ngDialogService.alertError(res.message);
        }
      });
  }
}

export default technicalClarificaitonEditController;
